package kz.kstu.ds.main;

import kz.kstu.ds.settings.SettingsManager;
import kz.kstu.ds.utils.GUIFactory;
import kz.kstu.ds.utils.GUIIcon;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Date: 04.11.12
 * Time: 9:05
 *
 * @author Oleg Anastassov
 */
public class AboutFrame extends JFrame {

    private static final String TITLE = "Центр аутентификации";

    private static final int HEIGHT = 180;
    private static final int WIDTH = 400;

    private JPanel rootPanel;
    private JLabel appLabel;
    private JLabel versionLabel;
    private JLabel buildLabel;
    private JButton closeButton;

    public AboutFrame() {
        setTitle(TITLE);
        setSize(new Dimension(WIDTH, HEIGHT));
        setResizable(false);
        setContentPane(rootPanel);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);

        initData();
        initIcons();
        initListeners();
    }

    private void initData() {
        SettingsManager manager = SettingsManager.getInstance();
        appLabel.setText(manager.getValue(SettingsManager.APP_NAME));
        versionLabel.setText(manager.getValue(SettingsManager.APP_VERSION));
        buildLabel.setText("r." +manager.getValue(SettingsManager.APP_BUILD));
    }

    private void initIcons() {
        setIconImage(GUIFactory.getImage(GUIIcon.ABOUT));
        closeButton.setIcon(GUIFactory.getIcon(GUIIcon.CLOSE));
    }

    private void initListeners() {
        closeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
    }


}
